package ex.datastream.functions.sourceFunction;

import ex.vo.Event;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Random;

/**
 *  
 */
public class SourceFuncByEvent implements SourceFunction<Event> {
    private boolean isRunning = true;

    @Override
    public void run(SourceContext<Event> ctx) throws Exception {
        while (isRunning) {
            Event item = generateItem();
            ctx.collect(item);
            Thread.sleep(200);//TimeEvictorTest.java测试修改为1000

        }
    }

    @Override
    public void cancel() {
        isRunning=false;
    }

    private Event generateItem() {
        int i = new Random().nextInt(100);
        Event item = new Event();
        item.key= i;
        item.timestamp=System.currentTimeMillis()+1000;//TimeEvictorTest.java测试修改为+1000
        return item;
    }


}
